package servicos;

import java.util.List;

import persistencia.ClienteDAO;

import persistencia.base.DAOException;
import persistencia.base.DAOFactory;
import dominio.Cliente;

public class ClienteRN {

	private ClienteDAO clienteDao = DAOFactory.getClienteDAO();

	public void salvar(Cliente cliente) throws FalhaDeInclusaoException {

		try {

			clienteDao.getSession().beginTransaction();
			clienteDao.save(cliente);
			clienteDao.getSession().getTransaction().commit();

		} catch (DAOException e) {
			e.printStackTrace();
			throw new FalhaDeInclusaoException();
		}
	}

	public List<Cliente> listar() throws FalhaDeInclusaoException {

		try {
			return clienteDao.findAll();

		} catch (DAOException e) {
			e.printStackTrace();
			throw new FalhaDeInclusaoException();
		}
	}

	public void deletar(Cliente cliente) throws FalhaDeDeletarExcepiton {
		try {
			clienteDao.getSession().beginTransaction();
			clienteDao.delete(cliente);
			clienteDao.getSession().getTransaction().commit();

		} catch (DAOException e) {
			e.printStackTrace();
			throw new FalhaDeDeletarExcepiton();
		}

	}

	
}
